/**
 * Copyright 2009-2010 - YangJiandong(chunquedong)
 * 
 * This file is part of ChunMap project
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
 * 你可以自由复制、传播本项目的下载包文件，但必须保持其完整性。
 * 我们不用对使用中的风险及由此造成的损失承担任何责任。
 * 详细情况请见《ChunMap许可协议》。

 * 想了解更多有关ChunMap的信息，请访问http://code.google.com/p/chunmap/
 */
package chunmap.example;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;

import chunmap.app.MapCtrl;
import chunmap.app.MapPanel;
import chunmap.app.tools.SelectTool;

/**
 * 地图界面表单基类
 * 
 * @author chunquedong
 * 
 */
public abstract class BaseMap {

	protected JFrame frame;
	protected MapCtrl map;
	protected SelectTool tool=new SelectTool();
	
	public void init() {
	
		//create frame
		frame = new JFrame("温馨提示：滚珠缩放，右键拖动");
		frame.setLocation(100, 100);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(850, 700);
		frame.setLayout(new FlowLayout());
	
		//get map panel
		final MapPanel ui = initMap();
		
		frame.add(ui);
		addButton();
		
		//show frame
		frame.setVisible(true);
	}

	private MapPanel initMap() {
		MapPanel ui = new MapPanel(800, 510);
		ui.setPreferredSize(new Dimension(800, 510));
		map = ui.getMap();

		addLayer(map);

		map.fullView();
		map.refreshMap();
		return ui;
	}
	
	protected void addButton(){
		UiUtil.addCommonButton(frame,map);
		UiUtil.addButton(frame,map,"选择",new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				map.setCurrentPlug(tool);
			}
		});
	}

	protected abstract void addLayer(MapCtrl map);
}
